how to deploy project with jenkins pipeline script on kubernetes1.19

  1. install pipeline plugin, git parameter plugin

  2. get credentialsId from manage credentials

  3. add docker repository in maven settings.xml

    <server>
        <id>docker-repo</id>
        <username>user</username>
        <password>password</password>
        <configuration>
            <email>eamil</email>
        </configuration>
    </server>
    
  4. create image pull secret in kubernetes, add imagePullSecrets in k8s yaml

    kubectl create secret docker-registry chenshi --docker-username=user --docker-password=password --docker-email=email
    
    spec:
      containers:
      - name: nginx
      imagePullSecrets:
      - name: myregistrykey
    
  5. pipeline script

    pipeline {
    
        agent any
    
        stages {
            stage('checkout') {
                steps {
                    dir('/projects/project1/') {
                        git branch: "${branch}",
                        credentialsId: 'from manage credentials',
                        url: 'https://chenshi.de/projects/project1/'
                    }
                }
            }
            stage('build') {
                steps {
                    dir('/projects/project1/') {
                        sh'''
                        mvn clean package -Ddocker-image.tag=${dockerTag} -DpushImage
                        #rm -rf /projects/project1/dist/ && yarn && yarn build && docker build -t chenshi.de/project:${tag} . && docker push chenshi.de/project:${tag}
                        '''
                    }
                }
            }
            stage('deploy') {
                steps {
                    sh '''
                    /scrips/project1.sh ${tag}
                    '''
                    }
                }
            }
    }
    
  6. references:

    http://dmp.fabric8.io/#authentication

    https://www.ibm.com/support/knowledgecenter/en/SSBS6K_2.1.0.3/manage_images/imagepullsecret.html